package cz.muni.fi.pa165.soap.client;

import cz.muni.fi.pa165.soap.EmployeeDTO;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.List;

/**
 *
 * @author shifty
 */
public class EmployeeTableModel extends TableModel {
    
    public EmployeeTableModel(String[] columns) {
        super(columns);
    }
    
    public void setValuesFromList(List<EmployeeDTO> list) {
        Object[][] values = new Object[list.size()][getColumnCount()];
        int i=0;
        DateFormat df;
        if(MainFrame.RB != null && MainFrame.RB.getLocale() != null) {
            df = DateFormat.getDateInstance(DateFormat.MEDIUM, MainFrame.RB.getLocale());
        } else {
            df = new SimpleDateFormat("dd.MM.yyyy");    
            
        }
        for(EmployeeDTO e : list) {
            values[i][0]=e.getId();
            values[i][1]=e.getName();
            values[i][2]=df.format(e.getBirthDate().toGregorianCalendar().getTime());
            values[i][3]=e.getPassword();
            values[i][4]=MainFrame.RB.getString(e.getRole().toString());
            i++;
        }
        setValues(values);
    } 
    
}
